package cn.iocoder.yudao.module.system.controller.admin.mini.orderInfo.order.dal.mysql.order;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.controller.admin.mini.orderInfo.order.controller.admin.order.vo.OrderExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mini.orderInfo.order.controller.admin.order.vo.OrderPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mini.orderInfo.order.dal.dataobject.order.OrderDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 小程序-订单 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface OrderMapper extends BaseMapperX<OrderDO> {

    default PageResult<OrderDO> selectPage(OrderPageReqVO reqVO) {

        LambdaQueryWrapperX<OrderDO> lqw = new LambdaQueryWrapperX<OrderDO>()
                .betweenIfPresent(OrderDO::getCreateTime, reqVO.getCreateTime())
                .likeIfPresent(OrderDO::getOrderCode, reqVO.getOrderCode())
                .eqIfPresent(OrderDO::getOrderStatus, reqVO.getOrderStatus())
                .eqIfPresent(OrderDO::getAddress, reqVO.getAddress())
                .eqIfPresent(OrderDO::getLogistic, reqVO.getLogistic())
                .eqIfPresent(OrderDO::getGoods, reqVO.getGoods())
                .eqIfPresent(OrderDO::getPayStatus, reqVO.getPayStatus())
                .betweenIfPresent(OrderDO::getPayTime, reqVO.getPayTime())
                .betweenIfPresent(OrderDO::getLogisticTime, reqVO.getLogisticTime())
                .betweenIfPresent(OrderDO::getConfirmTime, reqVO.getConfirmTime())
                .betweenIfPresent(OrderDO::getAddTime, reqVO.getAddTime())
                .eqIfPresent(OrderDO::getTotalAmount, reqVO.getTotalAmount())
                .eqIfPresent(OrderDO::getDeduction, reqVO.getDeduction())
                .orderByDesc(OrderDO::getId);

        //1使用
        Integer isVoucher = reqVO.getIsVoucher();
        if (isVoucher!=null){
            if (isVoucher==1)
                lqw.isNotNull(OrderDO::getBalanceId);
            if (isVoucher==2)
                lqw.isNull(OrderDO::getBalanceId);
        }

        return selectPage(reqVO,lqw);

    }

    default List<OrderDO> selectList(OrderPageReqVO reqVO) {
        LambdaQueryWrapperX<OrderDO> lqw = new LambdaQueryWrapperX<OrderDO>()
                .betweenIfPresent(OrderDO::getCreateTime, reqVO.getCreateTime())
                .likeIfPresent(OrderDO::getOrderCode, reqVO.getOrderCode())
                .eqIfPresent(OrderDO::getOrderStatus, reqVO.getOrderStatus())
                .eqIfPresent(OrderDO::getAddress, reqVO.getAddress())
                .eqIfPresent(OrderDO::getLogistic, reqVO.getLogistic())
                .eqIfPresent(OrderDO::getGoods, reqVO.getGoods())
                .eqIfPresent(OrderDO::getPayStatus, reqVO.getPayStatus())
                .betweenIfPresent(OrderDO::getPayTime, reqVO.getPayTime())
                .betweenIfPresent(OrderDO::getLogisticTime, reqVO.getLogisticTime())
                .betweenIfPresent(OrderDO::getConfirmTime, reqVO.getConfirmTime())
                .betweenIfPresent(OrderDO::getAddTime, reqVO.getAddTime())
                .eqIfPresent(OrderDO::getTotalAmount, reqVO.getTotalAmount())
                .eqIfPresent(OrderDO::getDeduction, reqVO.getDeduction())
                .orderByDesc(OrderDO::getId);

        //1使用
        Integer isVoucher = reqVO.getIsVoucher();
        if (isVoucher!=null){
            if (isVoucher==1)
                lqw.isNotNull(OrderDO::getBalanceId);
            if (isVoucher==2)
                lqw.isNull(OrderDO::getBalanceId);
        }
        return selectList(lqw);
    }

    default List<OrderDO> selectList(OrderExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<OrderDO>()
                .betweenIfPresent(OrderDO::getCreateTime, reqVO.getCreateTime())
                .likeIfPresent(OrderDO::getOrderCode, reqVO.getOrderCode())
                .eqIfPresent(OrderDO::getOrderStatus, reqVO.getOrderStatus())
                .eqIfPresent(OrderDO::getAddress, reqVO.getAddress())
                .eqIfPresent(OrderDO::getLogistic, reqVO.getLogistic())
                .eqIfPresent(OrderDO::getGoods, reqVO.getGoods())
                .eqIfPresent(OrderDO::getPayStatus, reqVO.getPayStatus())
                .betweenIfPresent(OrderDO::getPayTime, reqVO.getPayTime())
                .betweenIfPresent(OrderDO::getLogisticTime, reqVO.getLogisticTime())
                .betweenIfPresent(OrderDO::getConfirmTime, reqVO.getConfirmTime())
                .betweenIfPresent(OrderDO::getAddTime, reqVO.getAddTime())
                .eqIfPresent(OrderDO::getTotalAmount, reqVO.getTotalAmount())
                .eqIfPresent(OrderDO::getDeduction, reqVO.getDeduction())
                .orderByDesc(OrderDO::getId));
    }

}
